package com.limao.CacheManager;

import java.util.List;

import com.Hazelcast.Cache;
import com.Hazelcast.CacheFactory;
import com.limao.DBDataClass.SyshonoraryDataClass;
import com.limao.DBProvider.SyshonoraryProvider;
import com.limao.Tool.CacheClass;
import com.limao.cache.BasicModule;

public class SyshonoraryCacheManage  extends BasicModule{

	private SyshonoraryProvider provider;
	private static SyshonoraryCacheManage instance;
    
    public static SyshonoraryCacheManage getInstance() {
        return instance;
    }

    private Cache<String, SyshonoraryDataClass> Sys_honoraryManager;


    public SyshonoraryCacheManage() {
    	super("SyshonoraryCacheManage");
    	Sys_honoraryManager = CacheFactory.createCache("cd_SyshonoraryCacheManage");
		initProvider();

    }
    
    @Override
	public void initialize() {
        super.initialize();
        instance=this;
    }
    
    public void ClearObjectCache()
    {
		if(Sys_honoraryManager.size()>0)
		{
			Sys_honoraryManager.clear();
		}

    } 
    
	
	private void loadSysLevel()
	{
		if(Sys_honoraryManager.size()<=0)
		{
			List<SyshonoraryDataClass> list=provider.loadSysLevel();
			for(SyshonoraryDataClass obj:list)
			{
				Sys_honoraryManager.put(obj.honoraryid, obj);
			}
		}
	}
	
	public String loadUserHonoraryParam(int directlyman,int indirectlyman)
	{
		String honorary="新手";
		if(Sys_honoraryManager.size()<=0)
			loadSysLevel();
		for (String key : Sys_honoraryManager.keySet()) 
		{
			SyshonoraryDataClass obj=Sys_honoraryManager.get(key);
			if(directlyman>=CacheClass.getFloatValue(obj.directlyman_min) && indirectlyman>=CacheClass.getFloatValue(obj.indirectlyman_min))
			{
				honorary=obj.about;
				break;
			}
		}
		return honorary;
	}
	
	
	
	
	
	private void initProvider() {
		if (provider == null) {
			try {
				provider = SyshonoraryProvider.getInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
}
